<?php
	if (! isset ( $_SESSION ['member_is_admin'] ) || $_SESSION ['member_is_admin'] == '') {
		header ( "Location: index.php" );
	}
	
	//--
	$xtpl_main->assign ( "page_title", "Movie" );
	
	//-- Delete a movie
	if (isset ( $_GET ['del_movie_id'] )) {
		mysql_query ( "UPDATE movie SET movie_status = '2' WHERE movie_id = '" . $_GET ['del_movie_id'] . "'" );
		header ( "Location: ?mod=admin&act=movies" );
	}
	
	//-- List all movie
	$queryStringListAdminMovie =  ( "
									SELECT category.cate_name, movie.movie_id, movie.movie_name, movie.movie_status, movie.movie_description, movie_price 
									FROM category
									INNER JOIN movie ON category.cate_id = movie.cate_id 
									WHERE movie.movie_status <> '2'
							       " );
	//-- Filter by category
	if(isset($_GET['cid']) && $_GET['cid'] != ''){
		$queryStringListAdminMovie = $queryStringListAdminMovie . " AND category.cate_id = " . intval($_GET['cid']);
	}
	
	$resultListAdminMovie = mysql_query($queryStringListAdminMovie);
	
	$iCountAdminMovie = 0;
	while ( $rowListAdminMovie = mysql_fetch_array ( $resultListAdminMovie ) ) {
		$iCountAdminMovie ++;
		$rowListAdminMovie ['iCountAdminMovie'] = $iCountAdminMovie;
		
		//--
		if ($rowListAdminMovie ['movie_status'] == '1') {
			$rowListAdminMovie ['movie_status'] = 'active';
		} else {
			$rowListAdminMovie ['movie_status'] = 'inactive';
		}
		
		//-- Link edit
		$rowListAdminMovie ['movie_edit_link'] = '?mod=admin&act=movies-task&movie_id=' . $rowListAdminMovie ['movie_id'];
		
		//--
		$xtpl->assign ( 'list_admin_movie', $rowListAdminMovie );
		$xtpl->parse ( 'center.list_admin_movie' );
	}
	
	//-- List select-option category
	$rsSelectMoviesCategory = mysql_query("SELECT cate_id, cate_name FROM category WHERE cate_status = '1'");
	while($rowSelectMoviesCategory = mysql_fetch_array($rsSelectMoviesCategory)){
		if(isset($_GET['cid']) && $_GET['cid'] != '' && $rowSelectMoviesCategory['cate_id'] == $_GET['cid']){
			$rowSelectMoviesCategory['cate_selected'] = 'selected="selected"';
		}
		//--
		$xtpl->assign ( 'list_select_option_movie_cate', $rowSelectMoviesCategory );
		$xtpl->parse ( 'center.list_select_option_movie_cate' );
	}
?>


